//go:build wireinject
// +build wireinject

package wire

import (
	"context"
	"gin-vben-admin/internal/handler"
	"gin-vben-admin/internal/repository"
	"gin-vben-admin/internal/server"
	"gin-vben-admin/internal/service"
	"gin-vben-admin/pkg/app"
	"gin-vben-admin/pkg/captcha"
	"gin-vben-admin/pkg/db"
	"gin-vben-admin/pkg/jwt"
	"gin-vben-admin/pkg/server/http"
	"github.com/google/wire"
	"go.uber.org/zap"
)

var pkgSet = wire.NewSet(
	db.NewDB,
	jwt.NewJwt,
	captcha.NewCaptcha,
)

var repositorySet = wire.NewSet(
	repository.NewRepository,
	repository.NewTransaction,
	repository.NewSysUserRepository,
	repository.NewSysMenuRepository,
	repository.NewSysRoleRepository,
	repository.NewSysDeptRepository,
)

var serviceSet = wire.NewSet(
	service.NewService,
	service.NewLoginService,
	service.NewSysUserService,
	service.NewSysRoleService,
	service.NewSysMenuService,
	service.NewSysDeptService,
)

var handlerSet = wire.NewSet(
	handler.NewHandler,
	handler.NewLoginHandler,
	handler.NewCommonHandler,
	handler.NewSysUserHandler,
	handler.NewSysMenuHandler,
	handler.NewSysRoleHandler,
	handler.NewSysDeptHandler,
)

var serverSet = wire.NewSet(
	server.NewHTTPServer,
	server.NewJob,
	server.NewTask,
)

// build App
func newApp(httpServer *http.Server, job *server.Job, task *server.Task) *app.App {
	return app.NewApp(
		//app.WithServer(httpServer, job, task),
		app.WithServer(httpServer, job),
		app.WithName("demo-server"),
	)
}

func NewWire(context.Context, *zap.Logger, *handler.AssetsHandler, *db.Config, *http.Config, *jwt.Config, *captcha.Config, *service.Config) (*app.App, func(), error) {
	panic(wire.Build(
		pkgSet,
		repositorySet,
		serviceSet,
		handlerSet,
		serverSet,
		newApp,
	))
}
